#include "lolevel.h"
#include "platform.h"
#include "core.h"
#include "conf.h"

// via _sub_FF935BCC__SsCaptureSeq.c__0
static long *nrflag = (long*)0x9268; // see 0xFF935C38

#include "../../../generic/capt_seq.c"

void __attribute__((naked,noinline)) capt_seq_task() {
 // _sub_FF868B98__SsShootTask.c__13 (via taskcreate_CaptSeqTask)
 asm volatile (
                 "STMFD   SP!, {R3-R9,LR}\n"
                 "LDR     R6, =0x52F0\n"
                 "LDR     R4, =0x1AF4C\n"
                 "MOV     R9, #1\n"
                 "MOV     R7, #0\n"
 "loc_FF861D10:\n"
                 "LDR     R0, [R6,#0xC]\n"
                 "MOV     R2, #0\n"
                 "MOV     R1, SP\n"
                 "BL      sub_FF827098\n"
                 "TST     R0, #1\n"
                 "BEQ     loc_FF861D3C\n"
                 "LDR     R1, =0x539\n"
                 "LDR     R0, =0xFF861840\n"
                 "BL      sub_FF81B1CC\n"
                 "BL      sub_FF81B184\n"
                 "LDMFD   SP!, {R3-R9,PC}\n"
 "loc_FF861D3C:\n"
                 "LDR     R0, [SP]\n"
                 "LDR     R1, [R0]\n"
                 "CMP     R1, #0x1F\n"
                 "ADDLS   PC, PC, R1,LSL#2\n"
                 "B       loc_FF861FA0\n"
 "loc_FF861D50:\n"
                 "B       loc_FF861DD0\n"
 "loc_FF861D54:\n"
                 "B       loc_FF861E34\n"
 "loc_FF861D58:\n"
                 "B       loc_FF861E3C\n"
 "loc_FF861D5C:\n"
                 "B       loc_FF861E54\n"
 "loc_FF861D60:\n"
                 "B       loc_FF861E48\n"
 "loc_FF861D64:\n"
                 "B       loc_FF861E5C\n"
 "loc_FF861D68:\n"
                 "B       loc_FF861E64\n"
 "loc_FF861D6C:\n"
                 "B       loc_FF861E6C\n"
 "loc_FF861D70:\n"
                 "B       loc_FF861EC4\n"
 "loc_FF861D74:\n"
                 "B       loc_FF861EEC\n"
 "loc_FF861D78:\n"
                 "B       loc_FF861ED0\n"
 "loc_FF861D7C:\n"
                 "B       loc_FF861EDC\n"
 "loc_FF861D80:\n"
                 "B       loc_FF861EE4\n"
 "loc_FF861D84:\n"
                 "B       loc_FF861EF4\n"
 "loc_FF861D88:\n"
                 "B       loc_FF861EFC\n"
 "loc_FF861D8C:\n"
                 "B       loc_FF861F04\n"
 "loc_FF861D90:\n"
                 "B       loc_FF861F0C\n"
 "loc_FF861D94:\n"
                 "B       loc_FF861F14\n"
 "loc_FF861D98:\n"
                 "B       loc_FF861F1C\n"
 "loc_FF861D9C:\n"
                 "B       loc_FF861F24\n"
 "loc_FF861DA0:\n"
                 "B       loc_FF861F30\n"
 "loc_FF861DA4:\n"
                 "B       loc_FF861F38\n"
 "loc_FF861DA8:\n"
                 "B       loc_FF861F40\n"
 "loc_FF861DAC:\n"
                 "B       loc_FF861F48\n"
 "loc_FF861DB0:\n"
                 "B       loc_FF861F50\n"
 "loc_FF861DB4:\n"
                 "B       loc_FF861F5C\n"
 "loc_FF861DB8:\n"
                 "B       loc_FF861F64\n"
 "loc_FF861DBC:\n"
                 "B       loc_FF861F6C\n"
 "loc_FF861DC0:\n"
                 "B       loc_FF861F74\n"
 "loc_FF861DC4:\n"
                 "B       loc_FF861F7C\n"
 "loc_FF861DC8:\n"
                 "B       loc_FF861F88\n"
 "loc_FF861DCC:\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861DD0:\n"
                 "BL      sub_FF8625F4\n"
                 "BL      shooting_expo_param_override\n"  // +
                 "BL      sub_FF85FDFC\n"

 //  this code added to avoid some incorrect behavior if overrides are used.
 //  but it can cause some unexpected side effects. In this case, remove this code!

                 "MOV     R0, #0\n"
                 "STR     R0, [R4,#0x24]\n"  // fixes overrides  behavior at short shutter press
 	
 //  end of my code

                 "LDR     R0, [R4,#0x24]\n"
                 "CMP     R0, #0\n"
                 "BEQ     loc_FF861FAC\n"
                 "BL      sub_FF861518\n"
                 "MOV     R5, R0\n"
                 "LDR     R0, [R4,#0x24]\n"
                 "CMP     R0, #0\n"
                 "BEQ     loc_FF861E18\n"
                 "MOV     R0, #0xC\n"
                 "BL      sub_FF865A7C\n"
                 "TST     R0, #1\n"
                 "STRNE   R9, [R6,#4]\n"
                 "LDRNE   R0, [R5,#8]\n"
                 "ORRNE   R0, R0, #0x40000000\n"
                 "STRNE   R0, [R5,#8]\n"
                 "BNE     loc_FF861FAC\n"
 "loc_FF861E18:\n"
                 "MOV     R0, R5\n"
                 "BL      sub_FF8617C4\n"
                 "MOV     R0, R5\n"
                 "BL      sub_FF935BC8_my\n"             // ----------->
                 "BL      capt_seq_hook_raw_here\n"      // +
                 "TST     R0, #1\n"
                 "STRNE   R9, [R6,#4]\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861E34:\n"
                 "BL      sub_FF8620C4_my\n"             // ----------->
                 "B       loc_FF861E4C\n"
 "loc_FF861E3C:\n"
                 "MOV     R0, #1\n"
                 "BL      sub_FF86280C\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861E48:\n"
                 "BL      sub_FF862258\n"
 "loc_FF861E4C:\n"
                 "STR     R7, [R4,#0x24]\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861E54:\n"
                 "BL      sub_FF8625D4\n"
                 "B       loc_FF861E4C\n"
 "loc_FF861E5C:\n"
                 "BL      sub_FF8625DC\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861E64:\n"
                 "BL      sub_FF86272C\n"
                 "B       loc_FF861EC8\n"
 "loc_FF861E6C:\n"
                 "LDR     R5, [R0,#0xC]\n"
                 "BL      sub_FF8625E4\n"
                 "MOV     R0, R5\n"
                 "BL      sub_FF934B78\n"
                 "TST     R0, #1\n"
                 "MOV     R8, R0\n"
                 "BNE     loc_FF861EAC\n"
                 "BL      sub_FF871938\n"
                 "STR     R0, [R5,#0x18]\n"
                 "MOV     R0, R5\n"
                 "BL      sub_FF935A84\n"
                 "MOV     R0, R5\n"
                 "BL      sub_FF935E90\n"
                 "MOV     R8, R0\n"
                 "LDR     R0, [R5,#0x18]\n"
                 "BL      sub_FF871B4C\n"
 "loc_FF861EAC:\n"
                 "BL      sub_FF8625D4\n"
                 "MOV     R2, R5\n"
                 "MOV     R1, #9\n"
                 "MOV     R0, R8\n"
                 "BL      sub_FF860288\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861EC4:\n"
                 "BL      sub_FF86278C\n"
 "loc_FF861EC8:\n"
                 "BL      sub_FF85FDFC\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861ED0:\n"
                 "LDR     R0, [R4,#0x54]\n"
                 "BL      sub_FF862BA0\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861EDC:\n"
                 "BL      sub_FF862E50\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861EE4:\n"
                 "BL      sub_FF862EE0\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861EEC:\n"
                 "BL      sub_FF8625D4\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861EF4:\n"
                 "BL      sub_FF934D94\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861EFC:\n"
                 "BL      sub_FF934F7C\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F04:\n"
                 "BL      sub_FF93500C\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F0C:\n"
                 "BL      sub_FF9350C0\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F14:\n"
                 "BL      sub_FF9352C0\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F1C:\n"
                 "BL      sub_FF935318\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F24:\n"
                 "MOV     R0, #0\n"
                 "BL      sub_FF9353A0\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F30:\n"
                 "BL      sub_FF9354D8\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F38:\n"
                 "BL      sub_FF935568\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F40:\n"
                 "BL      sub_FF935628\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F48:\n"
                 "BL      sub_FF86298C\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F50:\n"
                 "BL      sub_FF862A2C\n"
                 "BL      sub_FF824944\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F5C:\n"
                 "BL      sub_FF93517C\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F64:\n"
                 "BL      sub_FF9351E8\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F6C:\n"
                 "BL      sub_FF864438\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F74:\n"
                 "BL      sub_FF8644A0\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F7C:\n"
                 "BL      sub_FF8644FC\n"
                 "BL      sub_FF8644BC\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861F88:\n"
                 "MOV     R0, #1\n"
                 "BL      sub_FF9366B0\n"
                 "LDRH    R0, [R4,#0x8C]\n"
                 "CMP     R0, #3\n"
                 "BLNE    sub_FF8646F8\n"
                 "B       loc_FF861FAC\n"
 "loc_FF861FA0:\n"
                 "LDR     R1, =0x65E\n"
                 "LDR     R0, =0xFF861840\n"
                 "BL      sub_FF81B1CC\n"
 "loc_FF861FAC:\n"
                 "LDR     R0, [SP]\n"
                 "LDR     R1, [R0,#4]\n"
                 "LDR     R0, [R6,#8]\n"
                 "BL      sub_FF8694D4\n"
                 "LDR     R5, [SP]\n"
                 "LDR     R0, [R5,#8]\n"
                 "CMP     R0, #0\n"
                 "LDREQ   R1, =0x11D\n"
                 "LDREQ   R0, =0xFF861840\n"
                 "BLEQ    sub_FF81B1CC\n"
                 "STR     R7, [R5,#8]\n"
                 "B       loc_FF861D10\n"
 );
} 



void __attribute__((naked,noinline)) sub_FF8620C4_my(){
 asm volatile(
                 "STMFD   SP!, {R4-R6,LR}\n"
                 "LDR     R4, [R0,#0xC]\n"
                 "LDR     R6, =0x1AF4C\n"
                 "LDR     R0, [R4,#8]\n"
                 "MOV     R5, #0\n"
                 "ORR     R0, R0, #1\n"
                 "STR     R0, [R4,#8]\n"
                 "LDR     R0, [R6,#0x24]\n"
                 "CMP     R0, #0\n"
                 "MOVEQ   R0, #2\n"
                 "BLEQ    sub_FF85BF28\n"
                 "BL      sub_FF8625E4\n"
                 "LDR     R0, [R6,#0x24]\n"
                 "CMP     R0, #0\n"
                 "BNE     loc_FF862174\n"
                 "MOV     R0, #0\n"
                 "BL      sub_FF9366B0\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF862934\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF9347C0\n"
                 "CMP     R0, #0\n"
                 "BEQ     loc_FF862144\n"
                 "BL      sub_FF9366F0\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF9348A4\n"
                 "TST     R0, #1\n"
                 "MOVNE   R2, R4\n"
                 "LDMNEFD SP!, {R4-R6,LR}\n"
                 "MOVNE   R1, #1\n"
                 "BNE     sub_FF860288\n"
                 "B       loc_FF862150\n"
 "loc_FF862144:\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF934840\n"
                 "BL      sub_FF9366F0\n"
 "loc_FF862150:\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF8617C4\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF935A84\n"
                 "BL      sub_FF936540\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF935BC8_my\n"             //----------->
                 "MOV     R5, R0\n"
                 "BL      capt_seq_hook_raw_here\n"      // +
                 "B       loc_FF862184\n"
 "loc_FF862174:\n"
                 "LDR     R0, =0x52F0\n"
                 "LDR     R0, [R0,#4]\n"
                 "CMP     R0, #0\n"
                 "MOVNE   R5, #0x1D\n"
 "loc_FF862184:\n"
                 "BL      sub_FF8644A0\n"
                 "BL      sub_FF8644E8\n"
                 "BL      sub_FF864528\n"
                 "MOV     R2, R4\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, R5\n"
                 "BL      sub_FF860288\n"
                 "BL      sub_FF935E20\n"
                 "CMP     R0, #0\n"
                 "LDRNE   R0, [R4,#8]\n"
                 "ORRNE   R0, R0, #0x2000\n"
                 "STRNE   R0, [R4,#8]\n"
                 "LDMFD   SP!, {R4-R6,PC}\n"
 );
}



void __attribute__((naked,noinline)) sub_FF935BC8_my(){
 asm volatile(
                 "STMFD   SP!, {R1-R7,LR}\n"
                 "MOV     R4, R0\n"
                 "BL      sub_FF936814\n"
                 "MVN     R1, #0x0\n"
                 "BL      sub_FF869508\n"
                 "MOV     R2, #4\n"
                 "ADD     R1, SP, #0x4\n"
                 "MOV     R0, #0x8A\n"
                 "BL      sub_FF8717A8\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0x373\n"
                 "LDRNE   R0, =0xFF935B94\n"
                 "BLNE    sub_FF81B1CC\n"
                 "LDR     R7, =0x1B00C\n"
                 "LDR     R6, =0x1AF4C\n"
                 "LDRSH   R1, [R7,#0xE]\n"
                 "LDR     R0, [R6,#0x88]\n"
                 "BL      sub_FF8F8F44\n"
                 "BL      sub_FF848C84\n"
                 "LDR     R3, =0x926C\n"
                 "STRH    R0, [R4,#0x94]\n"
                 "STR     R3, [SP]\n"
                 "MOV     R1, R0\n"
                 "LDRH    R0, [R6,#0x5C]\n"
                 "LDRSH   R2, [R7,#0xC]\n"
                 "SUB     R3, R3, #4\n"
                 "BL      sub_FF936E0C\n"
                 "BL      wait_until_remote_button_is_released\n"     // +
                 "BL      capt_seq_hook_set_nr\n"                     // +
                 "B       sub_FF935C34\n"                             // continue function in firmware
 );
}


/*************************************************************/
void __attribute__((naked,noinline)) exp_drv_task(){
 // task_ExpDrvTask
 asm volatile(
                 "STMFD   SP!, {R4-R8,LR}\n"
                 "SUB     SP, SP, #0x20\n"
                 "LDR     R8, =0xBB8\n"
                 "LDR     R7, =0x69C8\n"
                 "LDR     R5, =0x1FFC4\n"
                 "MOV     R0, #0\n"
                 "ADD     R6, SP, #0x10\n"
                 "STR     R0, [SP,#0xC]\n"
 "loc_FF8A4628:\n"
                 "LDR     R0, [R7,#0x20]\n"
                 "MOV     R2, #0\n"
                 "ADD     R1, SP, #0x1C\n"
                 "BL      sub_FF827098\n"
                 "LDR     R0, [SP,#0xC]\n"
                 "CMP     R0, #1\n"
                 "BNE     loc_FF8A4670\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R0, [R0]\n"
                 "CMP     R0, #0x13\n"
                 "CMPNE   R0, #0x14\n"
                 "CMPNE   R0, #0x15\n"
                 "BEQ     loc_FF8A478C\n"
                 "CMP     R0, #0x27\n"
                 "BEQ     loc_FF8A4764\n"
                 "ADD     R1, SP, #0xC\n"
                 "MOV     R0, #0\n"
                 "BL      sub_FF8A45B8\n"
 "loc_FF8A4670:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0]\n"
                 "CMP     R1, #0x2C\n"
                 "BNE     loc_FF8A46A0\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "BL      sub_FF8A5878\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R1, #1\n"
                 "BL      sub_FF8694D4\n"
                 "BL      sub_FF81B184\n"
                 "ADD     SP, SP, #0x20\n"
                 "LDMFD   SP!, {R4-R8,PC}\n"
 "loc_FF8A46A0:\n"
                 "CMP     R1, #0x2B\n"
                 "BNE     loc_FF8A46BC\n"
                 "LDR     R2, [R0,#0x88]!\n"
                 "LDR     R1, [R0,#4]\n"
                 "MOV     R0, R1\n"
                 "BLX     R2\n"
                 "B       loc_FF8A4BF8\n"
 "loc_FF8A46BC:\n"
                 "CMP     R1, #0x25\n"
                 "BNE     loc_FF8A470C\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R1, #0x80\n"
                 "BL      sub_FF869508\n"
                 "LDR     R0, =0xFF8A1058\n"
                 "MOV     R1, #0x80\n"
                 "BL      sub_FF927F78\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R2, R8\n"
                 "MOV     R1, #0x80\n"
                 "BL      sub_FF869414\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0xD36\n"
                 "BNE     loc_FF8A4750\n"
 "loc_FF8A46F8:\n"
                 "LDR     R1, [SP,#0x1C]\n"
                 "LDR     R0, [R1,#0x8C]\n"
                 "LDR     R1, [R1,#0x88]\n"
                 "BLX     R1\n"
                 "B       loc_FF8A4BF8\n"
 "loc_FF8A470C:\n"
                 "CMP     R1, #0x26\n"
                 "BNE     loc_FF8A475C\n"
                 "ADD     R1, SP, #0xC\n"
                 "BL      sub_FF8A45B8\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R1, #0x100\n"
                 "BL      sub_FF869508\n"
                 "LDR     R0, =0xFF8A1068\n"
                 "MOV     R1, #0x100\n"
                 "BL      sub_FF928200\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R2, R8\n"
                 "MOV     R1, #0x100\n"
                 "BL      sub_FF869414\n"
                 "TST     R0, #1\n"
                 "BEQ     loc_FF8A46F8\n"
                 "MOV     R1, #0xD40\n"
 "loc_FF8A4750:\n"
                 "LDR     R0, =0xFF8A1758\n"
                 "BL      sub_FF81B1CC\n"
                 "B       loc_FF8A46F8\n"
 "loc_FF8A475C:\n"
                 "CMP     R1, #0x27\n"
                 "BNE     loc_FF8A4774\n"
 "loc_FF8A4764:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "ADD     R1, SP, #0xC\n"
                 "BL      sub_FF8A45B8\n"
                 "B       loc_FF8A46F8\n"
 "loc_FF8A4774:\n"
                 "CMP     R1, #0x2A\n"
                 "BNE     loc_FF8A478C\n"
                 "BL      sub_FF8941A8\n"
                 "BL      sub_FF894E34\n"
                 "BL      sub_FF89496C\n"
                 "B       loc_FF8A46F8\n"
 "loc_FF8A478C:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "MOV     R4, #1\n"
                 "LDR     R1, [R0]\n"
                 "CMP     R1, #0x11\n"
                 "CMPNE   R1, #0x12\n"
                 "BNE     loc_FF8A47FC\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "ADD     R1, R1, R1,LSL#1\n"
                 "ADD     R1, R0, R1,LSL#2\n"
                 "SUB     R1, R1, #8\n"
                 "LDMIA   R1, {R2-R4}\n"
                 "STMIA   R6, {R2-R4}\n"
                 "BL      sub_FF8A30D8\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R3, [R0,#0x88]\n"
                 "LDR     R2, [R0,#0x8C]\n"
                 "ADD     R0, R0, #4\n"
                 "BLX     R3\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "BL      sub_FF8A5C4C\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R3, [R0,#0x90]\n"
                 "LDR     R2, [R0,#0x94]\n"
                 "ADD     R0, R0, #4\n"
                 "BLX     R3\n"
                 "B       loc_FF8A4B38\n"
 "loc_FF8A47FC:\n"
                 "CMP     R1, #0x13\n"
                 "CMPNE   R1, #0x14\n"
                 "CMPNE   R1, #0x15\n"
                 "BNE     loc_FF8A48B0\n"
                 "ADD     R3, SP, #0xC\n"
                 "MOV     R2, SP\n"
                 "ADD     R1, SP, #0x10\n"
                 "BL      sub_FF8A3320\n"
                 "CMP     R0, #1\n"
                 "MOV     R4, R0\n"
                 "CMPNE   R4, #5\n"
                 "BNE     loc_FF8A484C\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "MOV     R2, R4\n"
                 "LDR     R1, [R0,#0x7C]!\n"
                 "LDR     R12, [R0,#0xC]!\n"
                 "LDR     R3, [R0,#4]\n"
                 "MOV     R0, SP\n"
                 "BLX     R12\n"
                 "B       loc_FF8A4884\n"
 "loc_FF8A484C:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "CMP     R4, #2\n"
                 "LDR     R3, [R0,#0x8C]\n"
                 "CMPNE   R4, #6\n"
                 "BNE     loc_FF8A4898\n"
                 "LDR     R12, [R0,#0x88]\n"
                 "MOV     R0, SP\n"
                 "MOV     R2, R4\n"
                 "MOV     R1, #1\n"
                 "BLX     R12\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "MOV     R2, SP\n"
                 "ADD     R1, SP, #0x10\n"
                 "BL      sub_FF8A42CC\n"
 "loc_FF8A4884:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R2, [SP,#0xC]\n"
                 "MOV     R1, R4\n"
                 "BL      sub_FF8A4558\n"
                 "B       loc_FF8A4B38\n"
 "loc_FF8A4898:\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R12, [R0,#0x88]\n"
                 "ADD     R0, R0, #4\n"
                 "MOV     R2, R4\n"
                 "BLX     R12\n"
                 "B       loc_FF8A4B38\n"
 "loc_FF8A48B0:\n"
                 "CMP     R1, #0x21\n"
                 "CMPNE   R1, #0x22\n"
                 "BNE     loc_FF8A48FC\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "ADD     R1, R1, R1,LSL#1\n"
                 "ADD     R1, R0, R1,LSL#2\n"
                 "SUB     R1, R1, #8\n"
                 "LDMIA   R1, {R2-R4}\n"
                 "STMIA   R6, {R2-R4}\n"
                 "BL      sub_FF8A2664\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R3, [R0,#0x88]\n"
                 "LDR     R2, [R0,#0x8C]\n"
                 "ADD     R0, R0, #4\n"
                 "BLX     R3\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "BL      sub_FF8A2954\n"
                 "B       loc_FF8A4B38\n"
 "loc_FF8A48FC:\n"
                 "ADD     R1, R0, #4\n"
                 "LDMIA   R1, {R2,R3,R12}\n"
                 "STMIA   R6, {R2,R3,R12}\n"
                 "LDR     R1, [R0]\n"
                 "CMP     R1, #0x24\n"
                 "ADDLS   PC, PC, R1,LSL#2\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4918:\n"
                 "B       loc_FF8A49AC\n"
 "loc_FF8A491C:\n"
                 "B       loc_FF8A49AC\n"
 "loc_FF8A4920:\n"
                 "B       loc_FF8A4A00\n"
 "loc_FF8A4924:\n"
                 "B       loc_FF8A4A08\n"
 "loc_FF8A4928:\n"
                 "B       loc_FF8A4A08\n"
 "loc_FF8A492C:\n"
                 "B       loc_FF8A4A08\n"
 "loc_FF8A4930:\n"
                 "B       loc_FF8A49AC\n"
 "loc_FF8A4934:\n"
                 "B       loc_FF8A4A00\n"
 "loc_FF8A4938:\n"
                 "B       loc_FF8A4A08\n"
 "loc_FF8A493C:\n"
                 "B       loc_FF8A4A08\n"
 "loc_FF8A4940:\n"
                 "B       loc_FF8A4A20\n"
 "loc_FF8A4944:\n"
                 "B       loc_FF8A4A20\n"
 "loc_FF8A4948:\n"
                 "B       loc_FF8A4B0C\n"
 "loc_FF8A494C:\n"
                 "B       loc_FF8A4B14\n"
 "loc_FF8A4950:\n"
                 "B       loc_FF8A4B14\n"
 "loc_FF8A4954:\n"
                 "B       loc_FF8A4B14\n"
 "loc_FF8A4958:\n"
                 "B       loc_FF8A4B14\n"
 "loc_FF8A495C:\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4960:\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4964:\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4968:\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A496C:\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4970:\n"
                 "B       loc_FF8A4A10\n"
 "loc_FF8A4974:\n"
                 "B       loc_FF8A4A18\n"
 "loc_FF8A4978:\n"
                 "B       loc_FF8A4A18\n"
 "loc_FF8A497C:\n"
                 "B       loc_FF8A4A2C\n"
 "loc_FF8A4980:\n"
                 "B       loc_FF8A4A2C\n"
 "loc_FF8A4984:\n"
                 "B       loc_FF8A4A34\n"
 "loc_FF8A4988:\n"
                 "B       loc_FF8A4A64\n"
 "loc_FF8A498C:\n"
                 "B       loc_FF8A4A94\n"
 "loc_FF8A4990:\n"
                 "B       loc_FF8A4AC4\n"
 "loc_FF8A4994:\n"
                 "B       loc_FF8A4AF4\n"
 "loc_FF8A4998:\n"
                 "B       loc_FF8A4AF4\n"
 "loc_FF8A499C:\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A49A0:\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A49A4:\n"
                 "B       loc_FF8A4AFC\n"
 "loc_FF8A49A8:\n"
                 "B       loc_FF8A4B04\n"
 "loc_FF8A49AC:\n"
                 "BL      sub_FF8A1544\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4A00:\n"
                 "BL      sub_FF8A17CC\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4A08:\n"
                 "BL      sub_FF8A19D0\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4A10:\n"
                 "BL      sub_FF8A1C38\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4A18:\n"
                 "BL      sub_FF8A1E2C\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4A20:\n"
                 "BL      sub_FF8A2094_my\n"  //------------>
                 "MOV     R4, #0\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4A2C:\n"
                 "BL      sub_FF8A21D0\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4A34:\n"
                 "LDRH    R1, [R0,#4]\n"
                 "STRH    R1, [SP,#0x10]\n"
                 "LDRH    R1, [R5,#2]\n"
                 "STRH    R1, [SP,#0x12]\n"
                 "LDRH    R1, [R5,#4]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R5,#6]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R1, [R0,#0xC]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "BL      sub_FF8A58EC\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4A64:\n"
                 "LDRH    R1, [R0,#4]\n"
                 "STRH    R1, [SP,#0x10]\n"
                 "LDRH    R1, [R5,#2]\n"
                 "STRH    R1, [SP,#0x12]\n"
                 "LDRH    R1, [R5,#4]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R5,#6]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R1, [R5,#8]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "BL      sub_FF8A5A68\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4A94:\n"
                 "LDRH    R1, [R5]\n"
                 "STRH    R1, [SP,#0x10]\n"
                 "LDRH    R1, [R0,#6]\n"
                 "STRH    R1, [SP,#0x12]\n"
                 "LDRH    R1, [R5,#4]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R5,#6]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R1, [R5,#8]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "BL      sub_FF8A5B14\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4AC4:\n"
                 "LDRH    R1, [R5]\n"
                 "STRH    R1, [SP,#0x10]\n"
                 "LDRH    R1, [R5,#2]\n"
                 "STRH    R1, [SP,#0x12]\n"
                 "LDRH    R1, [R5,#4]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R5,#6]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R1, [R0,#0xC]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "BL      sub_FF8A5BB4\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4AF4:\n"
                 "BL      sub_FF8A2444\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4AFC:\n"
                 "BL      sub_FF8A2A58\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4B04:\n"
                 "BL      sub_FF8A2C90\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4B0C:\n"
                 "BL      sub_FF8A2E08\n"
                 "B       loc_FF8A4B18\n"
 "loc_FF8A4B14:\n"
                 "BL      sub_FF8A2FA0\n"
 "loc_FF8A4B18:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R3, [R0,#0x88]\n"
                 "LDR     R2, [R0,#0x8C]\n"
                 "ADD     R0, R0, #4\n"
                 "BLX     R3\n"
                 "CMP     R4, #1\n"
                 "BNE     loc_FF8A4B80\n"
 "loc_FF8A4B38:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "MOV     R2, #0xC\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "ADD     R1, R1, R1,LSL#1\n"
                 "ADD     R0, R0, R1,LSL#2\n"
                 "SUB     R4, R0, #8\n"
                 "LDR     R0, =0x1FFC4\n"
                 "ADD     R1, SP, #0x10\n"
                 "BL      sub_FFAD1868\n"
                 "LDR     R0, =0x1FFD0\n"
                 "MOV     R2, #0xC\n"
                 "ADD     R1, SP, #0x10\n"
                 "BL      sub_FFAD1868\n"
                 "LDR     R0, =0x1FFDC\n"
                 "MOV     R2, #0xC\n"
                 "MOV     R1, R4\n"
                 "BL      sub_FFAD1868\n"
                 "B       loc_FF8A4BF8\n"
 "loc_FF8A4B80:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R0, [R0]\n"
                 "CMP     R0, #0xB\n"
                 "BNE     loc_FF8A4BC8\n"
                 "MOV     R3, #0\n"
                 "STR     R3, [SP]\n"
                 "MOV     R3, #1\n"
                 "MOV     R2, #1\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, #0\n"
                 "BL      sub_FF8A134C\n"
                 "MOV     R3, #0\n"
                 "STR     R3, [SP]\n"
                 "MOV     R3, #1\n"
                 "MOV     R2, #1\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, #0\n"
                 "B       loc_FF8A4BF4\n"
 "loc_FF8A4BC8:\n"
                 "MOV     R3, #1\n"
                 "MOV     R2, #1\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, #1\n"
                 "STR     R3, [SP]\n"
                 "BL      sub_FF8A134C\n"
                 "MOV     R3, #1\n"
                 "MOV     R2, #1\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, #1\n"
                 "STR     R3, [SP]\n"
 "loc_FF8A4BF4:\n"
                 "BL      sub_FF8A148C\n"
 "loc_FF8A4BF8:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "BL      sub_FF8A5878\n"
                 "B       loc_FF8A4628\n"
 );
}

void __attribute__((naked,noinline)) sub_FF8A2094_my(){ // 
 asm volatile(
                 "STMFD   SP!, {R4-R8,LR}\n"
                 "LDR     R7, =0x69C8\n"
                 "MOV     R4, R0\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R1, #0x3E\n"
                 "BL      sub_FF869508\n"
                 "LDRSH   R0, [R4,#4]\n"
                 "MOV     R2, #0\n"
                 "MOV     R1, #0\n"
                 "BL      sub_FF8A10DC\n"
                 "MOV     R6, R0\n"
                 "LDRSH   R0, [R4,#6]\n"
                 "BL      sub_FF8A11EC\n"
                 "LDRSH   R0, [R4,#8]\n"
                 "BL      sub_FF8A1244\n"
                 "LDRSH   R0, [R4,#0xA]\n"
                 "BL      sub_FF8A129C\n"
                 "LDRSH   R0, [R4,#0xC]\n"
                 "BL      sub_FF8A12F4\n"
                 "MOV     R5, R0\n"
                 "LDR     R0, [R4]\n"
                 "LDR     R8, =0x1FFDC\n"
                 "CMP     R0, #0xB\n"
                 "MOVEQ   R6, #0\n"
                 "MOVEQ   R5, #0\n"
                 "BEQ     loc_FF8A2124\n"
                 "CMP     R6, #1\n"
                 "BNE     loc_FF8A2124\n"
                 "LDRSH   R0, [R4,#4]\n"
                 "LDR     R1, =0xFF8A1048\n"
                 "MOV     R2, #2\n"
                 "BL      sub_FF9280CC\n"
                 "STRH    R0, [R4,#4]\n"
                 "MOV     R0, #0\n"
                 "STR     R0, [R7,#0x28]\n"
                 "B       loc_FF8A212C\n"
 "loc_FF8A2124:\n"
                 "LDRH    R0, [R8]\n"
                 "STRH    R0, [R4,#4]\n"
 "loc_FF8A212C:\n"
                 "CMP     R5, #1\n"
                 "LDRNEH  R0, [R8,#8]\n"
                 "BNE     loc_FF8A2148\n"
                 "LDRSH   R0, [R4,#0xC]\n"
                 "LDR     R1, =0xFF8A10CC\n"
                 "MOV     R2, #0x20\n"
                 "BL      sub_FF8A58A8\n"
 "loc_FF8A2148:\n"
                 "STRH    R0, [R4,#0xC]\n"
                 "LDRSH   R0, [R4,#6]\n"
                 "BL      sub_FF893F18_my\n"   //------------>
                 "LDRSH   R0, [R4,#8]\n"
                 "MOV     R1, #1\n"
                 "BL      sub_FF894664\n"
                 "MOV     R1, #0\n"
                 "ADD     R0, R4, #8\n"
                 "BL      sub_FF8946EC\n"
                 "LDRSH   R0, [R4,#0xE]\n"
                 "BL      sub_FF89CD74\n"
                 "LDR     R4, =0xBB8\n"
                 "CMP     R6, #1\n"
                 "BNE     loc_FF8A21A0\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R2, R4\n"
                 "MOV     R1, #2\n"
                 "BL      sub_FF869414\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0x54D\n"
                 "LDRNE   R0, =0xFF8A1758\n"
                 "BLNE    sub_FF81B1CC\n"
 "loc_FF8A21A0:\n"
                 "CMP     R5, #1\n"
                 "LDMNEFD SP!, {R4-R8,PC}\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R2, R4\n"
                 "MOV     R1, #0x20\n"
                 "BL      sub_FF869414\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0x552\n"
                 "LDRNE   R0, =0xFF8A1758\n"
                 "LDMNEFD SP!, {R4-R8,LR}\n"
                 "BNE     sub_FF81B1CC\n"
                 "LDMFD   SP!, {R4-R8,PC}\n"
 );
}

void __attribute__((naked,noinline)) sub_FF893F18_my(){
 asm volatile(

                 "STMFD   SP!, {R4-R6,LR}\n"
                 "LDR     R5, =0x66F8\n"
                 "MOV     R4, R0\n"
                 "LDR     R0, [R5,#4]\n"
                 "CMP     R0, #1\n"
                 "MOVNE   R1, #0x140\n"
                 "LDRNE   R0, =0xFF893D1C\n"
                 "BLNE    sub_FF81B1CC\n"
                 "CMN     R4, #0xC00\n"
                 "LDREQSH R4, [R5,#2]\n"
                 "CMN     R4, #0xC00\n"
                 "LDREQ   R1, =0x146\n"
                 "LDREQ   R0, =0xFF893D1C\n"
                 "STRH    R4, [R5,#2]\n"
                 "BLEQ    sub_FF81B1CC\n"
                 "MOV     R0, R4\n"
//                 "BL      sub_FF9B943C\n"  // -
                 "BL      apex2us\n"         // +
                 "MOV     R4, R0\n"
//                 "BL      nullsub_70\n"  // why not?
                 "MOV     R0, R4\n"
                 "BL      sub_FF8C5190\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0x14B\n"
                 "LDMNEFD SP!, {R4-R6,LR}\n"
                 "LDRNE   R0, =0xFF893D1C\n"
                 "BNE     sub_FF81B1CC\n"
                 "LDMFD   SP!, {R4-R6,PC}\n"
 );
}
